﻿package remember.library.categories
{
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.events.Event;
	
	import flash.display.MovieClip;
	import remember.library.*;
	import remember.library.categories.Item;
	
	public class Categories extends MovieClip
	{
		public var mainLibrary;
		
		public var loader:URLLoader;
		public var xml:XML;
		
		function Categories () 
		{
			mainLibrary = this.parent;
			_loadXml();
		}
		
		private function _loadXml()
		{
			var url:String = "xml/library/categories.xml";
			var request:URLRequest = new URLRequest( url ) ;
			
			loader = new URLLoader();
			loader.addEventListener( Event.COMPLETE, _onXmlLoaded);
			loader.load( request ) ;
		}
		
		private function _onXmlLoaded (ev:Event) 
		{
			xml = new XML( loader.data ) ;
			mainLibrary.xml = xml;
			_build();
		}
		
		private function _build() 
		{
			for ( var i in mainLibrary.xml.item ) {
				var item:Item = new Item( mainLibrary.xml.item[i].name );
				item.y 		= item.height*i;
				item.id 	= mainLibrary.xml.item[i].id;
				addChild(item);
			}
		}
		
	}
}